<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">大码列表</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="批次号" prop="batchNumber">
          <el-input
            v-model="queryParams.batchNumber"
            placeholder="请输入批次号检索"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status" >
          <el-select
            v-model="queryParams.status"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" class="list-search btn-success" color="#5ED4D4"
            @click="handleQuery"
          >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="list-search"
            @click="resetQuery"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            class="btn-success"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd()"
            v-hasPermi="['system:productPalletCodeBindingRelationship:insert']"
          >新增</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="生产计划编码" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              {{ scope.row.productPlan.planCode }}
          </template>
        </el-table-column>
        <el-table-column label="产品名称" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              {{ scope.row.productPlan.productBasicName }}
          </template>
        </el-table-column>
        <el-table-column label="规格名称" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              {{ scope.row.productPlan.productName }}
          </template>
        </el-table-column>
        <el-table-column label="批次号" align="center" prop="batchNumber" :show-overflow-tooltip="true" width="120" />
        <el-table-column label="大码规格" align="center" prop="specs" :show-overflow-tooltip="true" width="100" />
        <el-table-column label="状态" align="center" prop="status" width="80">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#13C2C2">待绑定</div>
            <div v-if="scope.row.status == 1" style="color:#13C2C2">绑定中</div>
            <div v-if="scope.row.status == 2" style="color:#52C41A">已完成</div>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" fixed="right" width="170">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-if="scope.row.status == 0"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:productPalletCodeBindingRelationship:update']"
            >编辑</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleDetail(scope.row)"
              v-hasPermi="['system:productPalletCodeBindingRelationship:detail']"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              v-if="scope.row.status == 0"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:productPalletCodeBindingRelationship:deleteById']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { palletCodeList, palletCodeDelete } from '@/api/system/palletCode/palletCode';

export default {
  name: "list",
  data() {
    return {
      loading: true,
      total: 0,
      list:[],
      // 状态
      status:[
        {
          value:'0',
          label:'待绑定'
        },
        {
          value:'1',
          label:'绑定中'
        },
        {
          value:'2',
          label:'已完成'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNumber: undefined,
        status: undefined,
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      palletCodeList(this.addDateRange(this.queryParams)).then((res) => {
          this.list = res.rows
          this.total = res.total
          this.loading = false
        }
      );
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 新增
    handleAdd(){
      this.$router.push({ path:"/palletCode/add" })
    },
    // 编辑
    handleUpdate(row) {
      this.$router.push({ path:"/palletCode/edit", query:{id: row.id}})
    },
    // 详情
    handleDetail(row){
      this.$router.push({ path:"/palletCode/detail", query:{id: row.id}})
    },
    // 删除
    handleDelete(row){
      this.$modal.confirm('是否确认删除？').then(() => {
        palletCodeDelete(row.id).then(() => {
          this.getList()
          this.$modal.msgSuccess("删除成功")
        })
      }).catch(() => {})
    }
  }
}
</script>
